
<div class="layui-container" style="margin-top: 15px;">
    <div class="layui-btn-group">
        <button class="layui-btn all">获取全部数据</button>
        <button class="layui-btn left">获取左边数据</button>
        <button class="layui-btn right">获取右边数据</button>
    </div>
    <div id="root"></div>
</div>


<script>

    layui.use(['transferTable'], function(){
        var transferTable = layui.transferTable,$=layui.$;
        var cols = [
            {checkbox: true, fixed: true}
            ,{field:'id', title: 'ID'}
            ,{field:'username', title: '用户名'}
            ,{field:'sex', title: '性别'}
        ]

            var data1 = [
                {
                    id:'1',
                    username:'张三',
                    sex:0
                },
                {
                    id:'2',
                    username:'李四',
                    sex:0
                },
                {
                    id:'3',
                    username:'王五',
                    sex:0
                },
                {
                    id:'4',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'5',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'6',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'7',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'8',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'9',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'10',
                    username:'小赵',
                    sex:0
                },
                {
                    id:'11',
                    username:'小赵',
                    sex:0
                },
            ];
            var data2 = [];

        var v = transferTable.render({
            elem: '#root'
            // ,url: ['api.php?t=1','api.php?t=2']
            ,cols: [[cols],[cols]]
            ,page: [true,true]
            ,id:['addMember','removeMember']
            ,height:[500,500]
            ,where:{id:'1,2,3'}
            ,id_name:'id'
            ,title: ['未分组成员','小组成员']
            ,data: [data1, data2]
        })
//transfer.get(参数1:初始化返回值,参数2:获取数据[all,left,right,l,r],参数:指定数据字段)
        //获取数据
        $('.all').on('click',function () {
            var data = transferTable.get(v,'all');
            layer.msg(JSON.stringify(data))
        });
        $('.left').on('click',function () {
            var data = transferTable.get(v,'left','id');
            layer.msg(JSON.stringify(data))
        });
        $('.right').on('click',function () {
            var data = transferTable.get(v,'r');
            layer.msg(JSON.stringify(data))
        });
        $('#addMember').on('click',function(){
            // transferTable.reload('addMember',{
            //     page:{curr:1},
            //     where:{
            //         title: $('#title').val(),
            //         sex: $('#sex').val()
            //     }
            // })
            alert("dasdasd")
            var id = transferTable.get('removeMember');
            layer.msg(JSON.stringify(id));
        })

        $('#removeMember').on('click',function(){
            var id = transferTable.get('removeMember');
            layer.msg(JSON.stringify(id));
        })


    })
</script>
